toc - update active link in toc before expanding#9674
Merged
Conversation
toc expansion is controled by `toc-expand` and computed on client side once at initialization and then at scrolling. It is based on links in the toc that are active. Default is first link to be the active one. When no scrolling (body content height smaller than window height), we need to update the active link to be last section seen on screen, and do this before we expand the toc.
In case resize leads to no scroll bar, the toc should be expanded to show all the content.
4 tasks
[skip ci]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
toc expansion is controled by
toc-expandand computed on client side once at initialization and then at scrolling. It is based on links in the toc that are active. Default is first link to be the active one.When no scrolling (body content height smaller than window height), we need to update the active link to be last section seen on screen, and do this before we expand the toc.Welcome to the quarto GitHub repo!
solves #3178
Context
Active link in TOC is updated based on window and body size (to detect scroll bar) or based on scroll position
quarto-cli/src/resources/formats/html/quarto.js
Lines 130 to 159 in 99fad06
and expansion is done based on which
ulfrom the toc has active linkquarto-cli/src/resources/formats/html/quarto.js
Lines 716 to 760 in 99fad06
This works ok, but this is currently how we initialize
quarto-cli/src/resources/formats/html/quarto.js
Lines 762 to 766 in 3e0f3a5
and we only update on scrolling
quarto-cli/src/resources/formats/html/quarto.js
Lines 767 to 780 in 3e0f3a5
Notice the different order.
For the no scroll case, expanding before updating the active link does not work. This is because first link is made active by default, but then the update should see the no scroll bar and update the last link to be the active one. Then expansion should happen.
When we scroll this is the order - update active link then expand.
I think we should initialize the same way.
I also added this to the resize event because when windows is resized to a no scroll bar state, the toc expansion won't be updated anymore.
Hard to test in several cases, but I did test locally and I believe this change is safe going through the code logic in my head for what could happen.